package com.yaodian100.mall.activities;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.yaodian100.crm.activities.service.ActivitiesService;
import com.yaodian100.mall.member.util.UserData;

public class ActivitiesAction extends ActionSupport implements Preparable {
	@Autowired
	private ActivitiesService activitiesService;
	// 订单编号
	private String orderId;
	// 账号
	private String account;
	// 区域
	private String area;
	// 服务器
	private String server;
	private String loginresult;

	public String save() {
		loginresult = "";
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(
				ServletActionContext.HTTP_RESPONSE);
		UserData userData = new UserData(request, response);
		// String userName = userData.getLoginId();
		String userName = userData.getMemberId();

		String mobileNo = "";
		String choice = activitiesService.validationOrderId(userName, orderId);
		if ("error".equals(choice)) {
			loginresult = "orderId_error";
			return "error";
		}
		Object obj = activitiesService.createActivities(orderId, account, area, server, userName, mobileNo);

		if (obj == null) {
			loginresult = "orderId_repeat";
			return "error";
		} else {
			loginresult = "dialog";
		}
		return "success";
	}

	/**
	 * 转到彩虹岛抽奖页面
	 * 
	 * @return
	 */
	public String chdActivities() {
		// Option option = JspUtil.menuOption("SystemValue", "chd");
		// // 开始时间
		// String startTime = option.getMemo1();
		// String endTime = option.getMemo2();
		// Date currentdate = new Date();
		// SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
		// Long time = Long.parseLong(formatter.format(currentdate));
		//
		// if (Integer.valueOf(startTime) - time > 0) {
		// // 活动未开始
		// return "chd";
		// } else if (Integer.valueOf(endTime) - time > 0) {
		// // 活动进行中
		// return "chd";
		//
		// } else if (!(Integer.valueOf(endTime) - time > 0)) {
		// // 活动已结束
		// return "chdEnd";
		// }
		return "chd";
	}

	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub

	}

	public String getLoginresult() {
		return loginresult;
	}

	public void setLoginresult(String loginresult) {
		this.loginresult = loginresult;
	}

	public ActivitiesService getActivitiesService() {
		return activitiesService;
	}

	public void setActivitiesService(ActivitiesService activitiesService) {
		this.activitiesService = activitiesService;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}

	public String getServer() {
		return server;
	}

	public void setServer(String server) {
		this.server = server;
	}

}
